package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.ProductBrandDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.ProductBrandInfo;

/**
 * 
 * @description 产品品牌管理
 * @author Wangxuegang
 * @date 2012-9-13
 * 
 */
@Repository("productBrandDAO")
public class ProductBrandDAOImpl extends SuperDAO<ProductBrandInfo> implements
		ProductBrandDAO {

	/**
	 * 产品品牌分页查询
	 * 
	 * @param pageInruire
	 * @param baseQuery
	 * @return
	 */
	@Override
	public Pagination<ProductBrandInfo> queryPaginationList(
			ProductBrandInfo pageInruire) {
		Pagination<ProductBrandInfo> paginationList = null;
		Integer rowCount = queryRowCount(pageInruire);

		pageInruire.calculate();
		List<ProductBrandInfo> list = queryProductBrandInfoList(pageInruire);
		paginationList = this.queryPagination(rowCount, list, pageInruire);

		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param pageInruire
	 * @return
	 */
	private Integer queryRowCount(ProductBrandInfo pageInruire) {
		Integer rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.ProductBrandMapper.queryRowCount", pageInruire);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @return
	 */
	private List<ProductBrandInfo> queryProductBrandInfoList(
			ProductBrandInfo productBrandInfo) {
		List<ProductBrandInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.ProductBrandMapper.queryProductBrandInfoList",
				productBrandInfo);
		return list;
	}

	/**
	 * 查询品牌最大Id值
	 * 
	 */
	@Override
	public String query() {
		String brandId = null;
		brandId = this.getSqlSession().selectOne(
				"mybatis.xml.ProductBrandMapper.query");
		return brandId;
	}

	/**
	 * 品牌新增
	 * 
	 * @param productBrandInfo
	 */
	@Override
	public void insert(ProductBrandInfo productBrandInfo) {
		this.getSqlSession().insert("mybatis.xml.ProductBrandMapper.insert",
				productBrandInfo);

	}

	/**
	 * 根据品牌Id值，查询该品牌记录
	 * 
	 * @param goodsCategoryId
	 * @return
	 */
	@Override
	public ProductBrandInfo queryById(String goodsCategoryId) {
		ProductBrandInfo productBrandInfo = null;
		productBrandInfo = this.getSqlSession().selectOne(
				"mybatis.xml.ProductBrandMapper.queryById", goodsCategoryId);

		return productBrandInfo;
	}

	/**
	 * 品牌修改
	 * 
	 * @param productBrandInfo
	 */
	@Override
	public void update(ProductBrandInfo productBrandInfo) {
		this.getSqlSession().update("mybatis.xml.ProductBrandMapper.update",
				productBrandInfo);
	}

	/**
	 * 根据品牌名称，模糊查询
	 * 
	 * @param brandName
	 * @return
	 */
	@Override
	public List<ProductBrandInfo> queryByName(ProductBrandInfo productBrandInfo) {
		List<ProductBrandInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.ProductBrandMapper.queryByName", productBrandInfo);

		return list;
	}

	/**
	 * 查询该操作员，新增的品牌编号
	 * 
	 * @param productBrandInfo
	 * @return
	 */
	@Override
	public String queryNewBrandId(ProductBrandInfo productBrandInfo) {
		String brandId = null;
		brandId = this.getSqlSession().selectOne(
				"mybatis.xml.ProductBrandMapper.queryNewBrandId",
				productBrandInfo);
		return brandId;
	}

	/**
	 * 根据品牌名称，查询该品牌记录
	 * 
	 * @param gameName
	 * @return
	 */
	@Override
	public List<ProductBrandInfo> queryByBrandName(ProductBrandInfo productBrandInfo) {
		List<ProductBrandInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.ProductBrandMapper.queryByBrandName", productBrandInfo);

		return list;
	}

	/**
	 * 查询所有的品牌
	 * 
	 * @return
	 */
	@Override
	public List<ProductBrandInfo> queryAllBrand() {
		List<ProductBrandInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.ProductBrandMapper.queryAllBrand");

		return list;
	}

}
